import math
from polyevaluator import PolyEvaluator

# Utility class to compute root mean squared error.
class RMSE():

  def __init__(self):
    pass

  # The actual root mean square error.
  def rmse(self, weights, xvalues, yvalues):
    square_error = 0
    num_vals = len(xvalues)
    evaluator = PolyEvaluator(weights)
    for idx in range(0, num_vals):
      predicted_y = evaluator.evaluate(xvalues[idx]) 
      diff = predicted_y - yvalues[idx]
      square_error += diff**2

    mean_square_error = float(square_error) / num_vals 
    return math.sqrt(mean_square_error)
